package com.atguigu.springcloud.service.impl;

import com.atguigu.springcloud.service.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilderFactory;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;


/**
 * @author xiaolong
 * @version 1.0
 * @description: TODO
 * @date 2021/9/23 10:52
 */
@EnableBinding(Source.class) //定义消息的推送管道
public class MessageProviderImpl implements IMessageProvider {

    @Resource
    private MessageChannel output; //消息的发送管道

//    @Resource
//    private Source source;   //注入接口和注入MessageChannel的区别在于发送时需不需要调用接口内的方法


    public String send() {
        String serial = UUID.randomUUID().toString();
        //将写进管道，
//        source.output().send()

        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("*****" + serial);
        return null;
    }
}
